import axios from '@/libs/axios.js'
import baseUrl from './index'
let jsonHeaders = {'content-type': 'application/json;charset=UTF-8'}

// 模板列表
export const getTemplateData = (params,query) => {
    return axios({
        // url: `${baseUrl}/virtual/template/list`,
        url:`${baseUrl}/resource-manager/template/list`,
        method: 'post',
        data: JSON.stringify(params),
        params:query,
        headers: jsonHeaders,
    })
}
// 修改模板
export const modifyTemplate = (params,id) => {
    return axios({
        // url: `${baseUrl}/virtual/template/update/${id}`,
        url:`${baseUrl}/resource-manager/template/${id}`,
        method: 'put',
        params:params,
        headers: jsonHeaders,
    })
}
// 删除模板
export const delTemplate = (id) => {
    return axios({
        // url: `${baseUrl}/virtual/template/delete/${id}`,
        url:`${baseUrl}/resource-manager/template/${id}`,
        method: 'delete',
        headers: jsonHeaders,
    })
}
export const createTemplate = data => {
    return axios({
        url:`${baseUrl}/resource-manager/template/create`,
        method: 'POST',
        headers: jsonHeaders,
        data
    })
}
// 获取模板详情
export const getTempInfpByID = async (id) => {
    let res = await axios({
        url: `${baseUrl}/resource-manager/template/list`,
        method: 'post',
        params:{pageIndex:1,pageSie:1},
        data:{id:id},
        headers: jsonHeaders,
    }).catch(error => {
    	return Promise.reject(error)
    })
    let {code,data:{items:templates},message} = res.data;
    let template = templates.length > 0 ? templates[0] : {};
    return Promise.resolve({data:{code,data:template,message}})
}
// 导出json文件
export const importTemp = (id) => {
    return axios({
        // url: `${baseUrl}/virtual/template/file/${id}`,
        url:`${baseUrl}/resource-manager/template/file/${id}`,
        method: 'post',
        headers: jsonHeaders,
    })
}

//导入模板
export const inPutTemFile = (params) => {
    return axios({
        url: `${baseUrl}/resource-manager/template/add`,
        method: 'post',
        data: params,
        headers: jsonHeaders
    });
};

// 生成模板
export const templateAutomatic = (data) => {
    return axios({
        url: `${baseUrl}/resource-manager/template/automatic`,
        method: 'post',
        data: data,
        headers: jsonHeaders
    });
};